import {takeEvery,put} from 'redux-saga/effects';
import {GET_LIST,GET_HOME_List,LOADMOREDATA,GET_DETAIL_DATA,GET_LOGIN_DATA} from '../actionTypes'
import {getListDataAction,receiveHomeData,receiveMoreData,receiveDetailAction,receiveLoginAction} from '../actionCreator'
import axios from 'axios'
export const mysaga = function* mysaga(){
    yield takeEvery(GET_LIST, getListData);
}
function* getListData(){
    //console.log(store.getState().inputValue);
    let res = yield axios.get('/api/list.json');
   // console.log(res);
    let length = res.data.data.length;
    let action = getListDataAction(res.data.data,length);
    yield put(action);
}
export const mysaga1 = function* mysaga1(){
    yield takeEvery(GET_HOME_List, getTopicListData);
}

function* getTopicListData(){
    let res = yield axios.get('/api/home.json');
    //console.log(res);
    var action = receiveHomeData(res.data.topicList,res.data.contentList,res.data.recommendList,res.data.writingList);
    yield put(action);
   
}
export const mysaga2 = function* mysaga1(){
    yield takeEvery(LOADMOREDATA, getMoreData);
}

function* getMoreData(){
    let res = yield axios.get('/api/homeList.json');
    //console.log(res.data.data);
    var action = receiveMoreData(res.data.data);
    yield put(action);
   
}
export const mysaga3 = function* mysaga1(){
    yield takeEvery(GET_DETAIL_DATA, getDetailData);
}

function* getDetailData(){
    let res = yield axios.get('/api/detail.json');
    //console.log(res.data.data);
    var action = receiveDetailAction(res.data.data);
    yield put(action);
}
export const mysaga4 = function* mysaga1(){
    yield takeEvery(GET_LOGIN_DATA, getLoginData);
}

function* getLoginData(action){
    let res = yield axios.get('/api/login.json');
    //获取传递过来的参数
    //console.log(action.username,action.password);
    //console.log(res.data.data);
    //var action = receiveDetailAction(res.data.data);
   // yield put(action);
   let actions = receiveLoginAction(res.data.success);
   yield put(actions);
}